package com.twelve.all.base;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;

/**
 * Created by 张龙臣 on 2018/10/25.
 */

public class BaseFragment extends Fragment {


    public void refresh() {
        if (getActivity() != null && !getActivity().isFinishing()) {
            FragmentTransaction ft = null;
            Fragment parent = getParentFragment();
            if (parent == null)
                ft = getActivity().getSupportFragmentManager().beginTransaction();
            else
                ft = parent.getChildFragmentManager().beginTransaction();
            ft.detach(this);
            ft.attach(this);
            ft.commitAllowingStateLoss();
        }
    }

    public void finish() {
        if (getActivity() != null && isAdded()) {
            getActivity().finish();
        }
    }
}
